//
//  ViewController.m
//  RSAUtil
//
//  Created by ideawu on 7/14/15.
//  Copyright (c) 2015 ideawu. All rights reserved.
//

#import "ViewController.h"
#import "RSA.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
	[super viewDidLoad];


	NSString *pubkey = @"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAt7FjoT+SMDPAvk6+lcOD\ndx5vGjK8Wqkr+RXdW7O5cOC18coI5I5IR2yAjtRp1L4uZBCRFueuRzH62GffYNMG\n/0IEiUmp5n6tbI7IWP07ccV75uU7ryfcMiiCneAILsKTkgCCLDsXMidS7R94OXlh\nUPJ1ojE0b2U8WuoZJo7V1cTsSPH1UrbA8tj829RoyWL9g0Jg0lbPvnnLHXwnJykf\n8vEOA9ED3mu/Y+otgSy7ZO7wg3nqBw43isYL6mc84417hrdtIqHm7kOEFLd7nWA2\ncj7/wYFWn8EnrckbFkixTYKPejxMH5m/dt4KjMMblH3tqBq+C0kZfKBLkjvV/CRH\npwIDAQAB\n-----END PUBLIC KEY-----";
	NSString *privkey = @"-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEAt7FjoT+SMDPAvk6+lcODdx5vGjK8Wqkr+RXdW7O5cOC18coI\n5I5IR2yAjtRp1L4uZBCRFueuRzH62GffYNMG/0IEiUmp5n6tbI7IWP07ccV75uU7\nryfcMiiCneAILsKTkgCCLDsXMidS7R94OXlhUPJ1ojE0b2U8WuoZJo7V1cTsSPH1\nUrbA8tj829RoyWL9g0Jg0lbPvnnLHXwnJykf8vEOA9ED3mu/Y+otgSy7ZO7wg3nq\nBw43isYL6mc84417hrdtIqHm7kOEFLd7nWA2cj7/wYFWn8EnrckbFkixTYKPejxM\nH5m/dt4KjMMblH3tqBq+C0kZfKBLkjvV/CRHpwIDAQABAoIBAQCSdZgHL+WCEzFh\nSu2AAUPnjNdunvc4nduWnQ1CGVkIm9HVd42BlcQhVmxl9Qxwe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vt\nwae4tXxc51uTbiMUu7Chz6Jsp4ZjxAGE8FDPl2HWnFwPc//G3yQR0RGTLKN7OwBO\nCLiJykfimz8NVqhLgKlV0pY0ow32x6tshak/EBaOklKH4g9KVCNsgA==\n-----END RSA PRIVATE KEY-----";
	
	NSString *enc = [RSA encryptString:@"如果没有aa想就去执如果没有想如果没如果没有想清楚就去执有想清楚就去执行，要么是在过程中发现问题，逻辑反复更改，要么上线后才发现没有考虑周全，这都不是我们想要看到的。" publicKey:pubkey];
	NSLog(@"encrypted: %@", enc);
	
	
	enc = @"F+feHOH6807tUV/drvepAMzKlVKRsoDFRkFNfhS9kgVoBt2E6OnUIVw12l608yQGWiqtq8rgZgMY/VCQYZB+3r2rhDlyZ2fjo00sUFOp5BkNPFTs/NpQAolD6V3ifNgDmBQP92uVbxbod1pLRwLC0wLOhr5flQXvvobeg5KrDeE=";
	
	NSData *data = [[NSData alloc] initWithBase64EncodedString:enc options:NSDataBase64DecodingIgnoreUnknownCharacters];
	data = [RSA decryptData:data publicKey:pubkey];
	NSString *dec = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
	NSLog(@"decrypted: %@", dec);
}

@end
